Ext.define('IHC.controller.ihc.cadastros.IHC002ListController', { 
	extend: 'Ext.app.Controller',
	
	requires: [
		'IHC.model.Equipe',
		'IHC.store.ihc.cadastros.IHC002Equipe',
		'IHC.store.ihc.cadastros.IHC002Colaborador',
		'IHC.view.ihc.cadastros.IHC002ListView',
		'IHC.view.ihc.cadastros.IHC002MasterListView',
		'IHC.view.ihc.cadastros.IHC002DetailListView',
		'IHC.view.ihc.IHC002HelpWindow'
	],

	stores: [
		'IHC.store.ihc.cadastros.IHC002Equipe',
		'IHC.store.ihc.cadastros.IHC002Colaborador'
	],
	
	models: [
		'IHC.model.Equipe'
	],
	
	views: [
		'IHC.view.ihc.cadastros.IHC002ListView',
		'IHC.view.ihc.cadastros.IHC002MasterListView',
		'IHC.view.ihc.cadastros.IHC002DetailListView',
		'IHC.view.ihc.IHC002HelpWindow'
	],
	
	formModule: 'IHC.controller.ihc.cadastros',
	
	formName: 'IHC002',
	
	suffixName: '',
	
	mixins: [
		'InsoftExtUi.ux.mixins.controller.CrudMasterListMixin'
	],
	
	refs: [{ 
		selector: 'ihc002-list',
		xtype: 'ihc002-list',
		ref : 'principal',
		autoCreate: true
    }, {
        selector : 'ihc002-master-list',
        xtype : 'ihc002-master-list',
        ref : 'mainGrid',
        autoCreate : true
	}],
	
	init: function() {
		var me = this;
		
		if(!me.inited) {
			me.bindDefaultActions('#ihc002-master-list');
			me.recordStore = me.getStore('IHC.store.ihc.cadastros.IHC002Equipe');
		}
		
		me.control({
			'#ihc002-master-list' : {
				selectionchange: me.onSelectionChange
			},
	        "#ihc002-list button[action=helpRecord]" : {
	        	click : me.helpEquipe
	        }
		});
		
		me.inited = true; 
	},
	
	actionIndex : function() {
		var me = this,
			manager = me.getLocaleManager(),
			title = manager.get('ihc002.mainPanel.title');
		
		me.recordStore.load();
		me.application.addTab(this.getPrincipal(), 'IHC002', title);
		manager.applyLocalesFor('#IHC002Tab');
		me.application.runAction('IHC.controller.ihc.cadastros.IHC002DetailListController', 'Index');
	},
	
	getDetailInfo : function() {
		var me = this, 
			controller = me.getController('IHC.controller.ihc.cadastros.IHC002DetailListController');

		return { grid: controller.getMainGrid(), filterName: 'equipeFilter' }; 
	},
	
	onSelectionChange : function(model, selected, eOpts) {
		this.masterRecordChanged(selected[0]);
	},
    
    helpEquipe : function() {
    	var me = this,
    		window = me.getView('IHC.view.ihc.IHC002HelpWindow').create();
    	
    	window.show();
    }
	
});
